<script setup lang="ts">
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import AddFill from "@iconify-icons/ri/add-circle-line";
import { PlusSearch } from "plus-pro-components";
import {
  columns,
  childColumns,
  pagination,
  dataList,
  searchColumns,
  searchState,
  handleSearch,
  openDialog,
  handlePageChange,
  handleSizeChange
} from "./utils/hook";
</script>

<template>
  <div>
    <!-- 回款查询区域 -->
    <el-card shadow="never">
      <template #header>
        <span>回款记录查询</span>
      </template>
      <PlusSearch
        v-model="searchState"
        :columns="searchColumns"
        :has-unfold="false"
        @search="handleSearch"
      />
    </el-card>

    <!-- 回款列表区域 -->
    <PureTableBar title="" :columns="columns">
      <template #buttons>
        <el-button
          type="primary"
          size="small"
          :icon="useRenderIcon(AddFill)"
          @click="openDialog"
        >
          新增回款记录
        </el-button>
      </template>

      <template v-slot="{ dynamicColumns }">
        <!-- 回款记录列表 -->
        <pure-table
          :columns="dynamicColumns"
          :data="dataList"
          :pagination="pagination"
          @page-current-change="handlePageChange"
          @page-size-change="handleSizeChange"
        >
          <!-- 回款订单详情 -->
          <template #expand="{ row }">
            <pure-table
              :columns="childColumns"
              :data="row.order_details"
            ></pure-table>
            <div class="mt-4 p-3 bg-gray-50 rounded-lg">
              <div class="flex items-start">
                <span class="text-sm font-medium text-gray-700 mr-2 mt-0.5"
                  >回款备注:</span
                >
                <div class="flex-1 min-w-0">
                  <el-input
                    v-model="row.remark"
                    type="textarea"
                    :rows="2"
                    placeholder="请输入订单备注"
                    class="text-sm"
                  />
                </div>
              </div>
            </div>
          </template>
        </pure-table>
      </template>
    </PureTableBar>
  </div>
</template>

<style lang="scss" scoped></style>
